<?php

/**
 * Mailbox form.
 *
 * @package    sf_sandbox
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class frontendMailboxForm extends BaseMailboxForm
{
 public function configure()
  {
  	unset(
  		$this['created_at'],
  		$this['updated_at'],
  		$this['pub'],
  		$this['del_sender'],
  		$this['del_resiver'],
  		$this['comment'],
  		$this['translate'],
  		$this['fl_read'],
        $this['from_partner_id'],
        $this['to_partner_id'],
  		$this['to_id'],
  		$this['fl_translate']);


  	  $this->setWidgets(array(
      'id'               => new sfWidgetFormInputHidden(),
  	  'from_id'          => new sfWidgetFormInputHidden( array (), array ('value' => sfContext::getInstance()->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ))),
	  'mailimage'          => new sfWidgetFormInputFile( ),
  	  'body' => new sfWidgetFormTextarea(array(),array('class'=>'mailbox_body','style'=>'height: 200px; width:90%;')),
    ));

               ///// Ответ
                if(sfContext::getInstance()->getRequest()->getParameter('parent_id')){
                     $this->widgetSchema['parent_id']  = new sfWidgetFormInputHidden( array (), array ('value' => sfContext::getInstance()->getRequest()->getParameter('parent_id')));
                }

    		  /////Статус ссылки
		 if(!sfConfig::get('app_mail_personal') or sfConfig::get('app_mail_personal')==false)
		 {
		 		 $this->widgetSchema['title'] =  new sfWidgetFormInput(array(),array('size'=>50));
		 		 $this->widgetSchema['to_user'] =  new sfWidgetFormInputHidden(array(),array('size'=>10));
		 		 $this->widgetSchema->moveField('title', 'after', 'id');
		 		 $this->widgetSchema->moveField('to_user', 'after', 'id');
		 }
		 else
		 {
		 	$this->widgetSchema['to_user'] =  new sfWidgetFormInputHidden();

		 }
		 ////
		 
		$this->validatorSchema ['mailimage'] = new sfValidatorFile ( array ('required' => false, 
		'path' => sfConfig::get ( 'sf_web_dir' ) . '/uploads/mailimage', 
		'mime_types' => 'web_images', 'max_size' => 500000 ) );
		

    $this->widgetSchema->setLabels(array(
  		'body'   => __('Content'),
		'mailimage'   => __('Image'),
  	 ));

                $this->validatorSchema['title'] = new sfValidatorString(array('required' => true),array('required'=>'поле обязательно'));
                $this->validatorSchema['body'] = new sfValidatorString(array('required' => true),array('required'=>'поле обязательно'));
                $this->validatorSchema['parent_id'] = new  sfValidatorInteger(array('required' => false));

    $this->validatorSchema->setOption ( 'allow_extra_fields', true );
    $this->widgetSchema->setNameFormat('mailbox[%s]');

    //$this->embedI18n(sfContext::getInstance()->getUser()->getLangs());

      	   // $js_path = '/js/tiny_mce/tiny_mce.js';
           //sfContext::getInstance()->getResponse()->addJavascript($js_path);

  }
}
